<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./js/jquery.js"></script>
    <script src="./layer/layer.js"></script>
    <style>

    </style>
</head>

<body>
    <h1>登录</h1>

    <form>
        <p>
            用户名 <input name="user">
        </p>
        <p>
            密码 <input name="pwd">
        </p>
        <p>
            <input type="submit" value="登录">
        </p>
    </form>
    <script>
        $(function () {
            var index;
            $("form").on("submit", function () {

                var oUser = {};
                $.ajax({
                    url: "./sys/login",
                    type: "post",
                    data: $("form").serialize(),
                    beforeSend() {
                        index = layer.msg("正在登录中...")
                    }
                }).done(function (res) {
                    layer.close(index)
                    let { code, data, msg, token } = res;
                    layer.msg(msg)
                    if (code === 200) {
                        sessionStorage.setItem("userinfo",JSON.stringify(data.userInfo))
                        sessionStorage.setItem("menus",JSON.stringify(data.menus))
                        sessionStorage.setItem("perms",JSON.stringify(data.perms))
                        sessionStorage.setItem("token",token)

                        setTimeout(function () {
                            location="./index.html";
                        },300);
                    }
                })

                return false;
            })
        })

    </script>

</body>

</html>